package com.search_wheel.controller;

import com.search_wheel.pojo.vo.SearchResult;
import com.search_wheel.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

// 可选：REST API Controller（用于AJAX调用）
@RestController
@RequestMapping("/api")
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    /**
     * API搜索接口
     */
    @GetMapping("/search")
    public SearchResult<?> apiSearch(@RequestParam String keyword,
                                     @RequestParam(defaultValue = "all") String type,
                                     @RequestParam(defaultValue = "1") int page,
                                     @RequestParam(defaultValue = "10") int size,
                                     @RequestParam(defaultValue = "time") String sort) {
        return searchService.searchByType(keyword, type, page, size,sort);
    }

    /**
     * 搜索建议接口
     */
    @GetMapping("/suggestions")
    public java.util.List<String> suggestions(@RequestParam String keyword,
                                              @RequestParam(defaultValue = "5") int limit,
                                              @RequestParam(defaultValue = "time") String sort) {
        return searchService.getSearchSuggestions(keyword, limit,sort);
    }
}
